<?php

namespace app\common\model;

use app\common\model\artwork\Fbx;
use think\Model;
use traits\model\SoftDelete;

class Product extends Model
{

    use SoftDelete;


    // 表名
    protected $name = 'product';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
//        'status_text'
    ];
    protected $hidden = [
        'deletetime',
    ];

    const STATUS_OFF = 0;
    const STATUS_ON = 1;

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function category()
    {
        return $this->belongsTo(Category::class, 'category_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function fbx()
    {
        return $this
            ->hasOne(Fbx::class, 'id', 'fbx_id', [], 'LEFT')
            ->setEagerlyType(0);
    }


//    public function orderitem()
//    {
//        return $this->morphOne(OrderItem::class, ['data_type', 'data_id'], OrderItem::DATA_TYPE_PRODUCT);
//    }
}
